//
//  FocusDoctorDetailController.m
//  QuickCure1
//
//  Created by Haozhong Chen on 2016/10/31.
//  Copyright © 2016年 maoge. All rights reserved.
//

#import "FocusDoctorDetailController.h"
#import "NetWorkTool.h"
#import "FocusDoctorDetailData.h"
#import "FocusDoctorData.h"
#import <UIImageView+WebCache.h>
//#import "FocusDoctorDetailView.h"



@interface FocusDoctorDetailController ()
@property(nonatomic,strong)UIAlertController*alertVC;
@property(nonatomic,strong)FocusDoctorDetailData*otherData;
@property (weak, nonatomic) IBOutlet UIButton *consultButton;
@property (weak, nonatomic) IBOutlet UILabel *doctor_name;
@property (weak, nonatomic) IBOutlet UILabel *doctor_title_name;
@property (weak, nonatomic) IBOutlet UILabel *hospital_name;
@property (weak, nonatomic) IBOutlet UIButton *flower;
@property (weak, nonatomic) IBOutlet UIButton *operation_count;
@property (weak, nonatomic) IBOutlet UIButton *banner;
@property (weak, nonatomic) IBOutlet UIImageView *doctor_portrait;
@property (weak, nonatomic) IBOutlet UISegmentedControl *segmentControl;
@property (weak, nonatomic) IBOutlet UITextView *firstView;

@property (weak, nonatomic) IBOutlet UITextView *thirdView;

@property (weak, nonatomic) IBOutlet UITextView *secondView;


@end

@implementation FocusDoctorDetailController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self test8];
    [self test9];
    [self test10];
    
    UIBarButtonItem*item=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"shixin"] style:UIBarButtonItemStylePlain target:self action:@selector(clickCollectButon:)];
    //    [item setBackgroundImage:[UIImage imageNamed:@"shixin"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    
    
    
    [self.navigationItem setRightBarButtonItem:item];
    self.title=@"医生的基本信息";
    

    // Do any additional setup after loading the view from its nib.
}

//取消收藏
-(void)clickCollectButon:(UIBarButtonItem*)item
{

    [item setImage:[UIImage imageNamed:@"kongxin"]];
    [self.delegate deletaDataList];
    item.enabled=NO;
    
}
- (IBAction)clickSegmentControl:(id)sender
{
    switch (self.segmentControl.selectedSegmentIndex) {
        case 0:
            //将firstView移动到视图层的第一位
            [self.view bringSubviewToFront:self.firstView];
            [self.view bringSubviewToFront:self.thirdView];
            //            [_firstView reloadData];
            break;
        case 1:
            [self.view bringSubviewToFront:self.secondView];
            //            [_firstView reloadData];
            break;
        default:
            break;
    }

}




-(FocusDoctorDetailData*)otherData
{
    if (!_otherData)
    {
        _otherData=[[FocusDoctorDetailData alloc]init];
    }
    return _otherData;
}

- (IBAction)clickConsultButton:(id)sender {
    [self showAlertVC];
}


-(void)showAlertVC
{
    //弹框
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"医生关闭了咨询" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *sureBtn = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    self.alertVC=alertVc;
    [alertVc addAction:sureBtn];
    [self presentViewController:alertVc animated:YES completion:nil];
}
//10.医生简介接口 OK
-(void)test10{
    
    //请求地址: http://iosapi.itcast.cn/doctorReceivingSetting.json.php
    //    请求参数:{"doctor_id":300000315}
    
    NSString *urlString = kGetIntroductionUrl;
    NSDictionary *paramDic = @{
                               @"doctor_id":@300000315
                               };
    
    
//    [self loadUrl:urlString params:paramDic];
    [[NetWorkTool shareManager] POST_RequestWithUrlString:urlString parmas:paramDic successBloock:^(id responseObject) {
        
//        NSLog(@"responseObject = %@",responseObject);
        
        NSDictionary*dict=responseObject;
        
        NSDictionary*dictData=[dict objectForKey:@"data"];
        
        
        [self.otherData setValuesForKeysWithDictionary:dictData];
        
        /*
         Creates and returns an array from a json-array.
         This method is thread-safe.
         
         @param cls  The instance's class in array.
         @param json  A json array of `NSArray`, `NSString` or `NSData`.
         数组,字符串,NSData
         Example: [{"name","Mary"},{name:"Joe"}]
         
         @return A array, or nil if an error occurs.
         */
        
        //        NSArray<FocusDoctorDetailData *> *modelArray = [NSArray yy_modelArrayWithClass:[FocusDoctorDetailData class] json:dictData];
        
        
//        NSLog(@"%@",self.otherData);
        [self setupUI];
        
        
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"error = %@",error);
    }];

}

//9. 匹配到医生后，查看医生接诊条件  OK
-(void)test9{
    
    //请求地址: http://iosapi.itcast.cn/doctorReceivingSetting.json.php
    //    请求参数:{"doctor_id":300000315}
    
    NSString *urlString = kDoctorReceivingSetting;
    NSDictionary *paramDic = @{
                               @"doctor_id":@300000315
                               };
    
    
//    [self loadUrl:urlString params:paramDic];
    [[NetWorkTool shareManager] POST_RequestWithUrlString:urlString parmas:paramDic successBloock:^(id responseObject) {
        
//        NSLog(@"responseObject = %@",responseObject);
        
        NSDictionary*dict=responseObject;
        
        NSDictionary*dictData=[dict objectForKey:@"data"];
        
//        NSLog(@"%@",dictData[@"receiving_setting_extra"]);
        
//        [self.otherData setValue:dictData[@"receiving_setting_extra"] forKey:@"receiving_setting_extra"];
        [self.otherData setValuesForKeysWithDictionary:dictData];
//        NSLog(@"%@",[self.otherData valueForKey:@"receiving_setting_extra"]);
        /*
         Creates and returns an array from a json-array.
         This method is thread-safe.
         
         @param cls  The instance's class in array.
         @param json  A json array of `NSArray`, `NSString` or `NSData`.
         数组,字符串,NSData
         Example: [{"name","Mary"},{name:"Joe"}]
         
         @return A array, or nil if an error occurs.
         */
        
        //        NSArray<FocusDoctorDetailData *> *modelArray = [NSArray yy_modelArrayWithClass:[FocusDoctorDetailData class] json:dictData];
        
        
//        NSLog(@"%@",self.otherData);
        [self setupUI];
        
        
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"error = %@",error);
    }];

    
}

//8.获取医生基本信息接口 OK
-(void)test8
{
    
    //   doctor_id 医生编号
    //    请求地址: http://iosapi.itcast.cn/getDoctorInfo.json.php
    //    请求参数:{"user_id":1000089,"doctor_id":300000315}
    
    NSString *urlString = kGetDoctorInfoUrl;
    NSDictionary *paramDic = @{@"user_id":@1000089,
                               @"doctor_id":@300000315 //@200000094
                               };
    
    
//    [self loadUrl:urlString params:paramDic];
    [[NetWorkTool shareManager] POST_RequestWithUrlString:urlString parmas:paramDic successBloock:^(id responseObject) {
        
//        NSLog(@"responseObject = %@",responseObject);
        
        NSDictionary*dict=responseObject;
        
        NSDictionary*dictData=[dict objectForKey:@"data"];
        
        
        [self.otherData setValuesForKeysWithDictionary:dictData];
        
        /*
         Creates and returns an array from a json-array.
         This method is thread-safe.
         
         @param cls  The instance's class in array.
         @param json  A json array of `NSArray`, `NSString` or `NSData`.
         数组,字符串,NSData
         Example: [{"name","Mary"},{name:"Joe"}]
         
         @return A array, or nil if an error occurs.
         */
        
        //        NSArray<FocusDoctorDetailData *> *modelArray = [NSArray yy_modelArrayWithClass:[FocusDoctorDetailData class] json:dictData];
        
        
//        NSLog(@"%@",self.otherData);
        [self setupUI];
        
        
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"error = %@",error);
    }];

    
}





#pragma mark - setupUI
-(void)setupUI
{
    self.doctor_name.text=self.data.doctor_name;
    
//    [self.doctor_portrait sd_setImageWithURL:[NSURL URLWithString:self.data.doctor_portrait]];
    [self.doctor_portrait sd_setImageWithURL:[NSURL URLWithString:self.data.doctor_portrait] placeholderImage:[UIImage imageNamed:@"illness_img_person.png"] options:SDWebImageRetryFailed];
    
    
    self.doctor_title_name.text=self.data.doctor_title_name;
    
    //拼接
    NSString*department=self.otherData.department_name;
    if (department)
    {
        self.hospital_name.text=[self.data.doctor_hospital_name stringByAppendingString:[@"-" stringByAppendingString:department]];
    }
    else
    {
        self.hospital_name.text=self.data.doctor_hospital_name;
    }
    
    
    [self.flower setTitle:[@"鲜花量:" stringByAppendingString:self.data.flower] forState:UIControlStateNormal];
    
//    [self.flower setTitleColor:kThemeColor forState:UIControlStateNormal];
    
    
    [self.banner setTitle:[@"锦旗量:" stringByAppendingString:self.data.banner] forState:UIControlStateNormal];
    
    
//    [self.banner setTitleColor:kThemeColor forState:UIControlStateNormal];
    
    [self.operation_count setTitle:[@"预约量:" stringByAppendingString:self.data.operation_count] forState:UIControlStateNormal];
    
    
//    [self.operation_count setTitleColor:kThemeColor forState:UIControlStateNormal];
    
    [self.consultButton setBackgroundColor:kThemeColor];

    
    
    
   
    NSString*strIntro=self.otherData.introduction;
    if (strIntro) {
        self.secondView.text=strIntro;
    }
    else
    {
        self.secondView.text=@"你特么是不是傻,数据呢";
    }
    [self.view addSubview:self.secondView];
    
   
    NSMutableString*strSettings=[[NSMutableString alloc]init];
    for (NSString*temp in self.otherData.receiving_settings)
    {
        [strSettings appendString:temp];
        [strSettings appendString:@"\n"];
    }
    
    if (strSettings.length>1) {
        self.firstView.text=strSettings.copy;
    }
    else
    {
        self.firstView.text=@"网络太慢了,或者服务器是大坑逼,反正没有数据回来,凑合看吧,我草案从哦啊哦草哦啊哦草哦啊哦擦擦              不过话说回来我是不是很帅";
    }
    [self.view addSubview:self.firstView];
    
   
    NSString*strSetEx=self.otherData.receiving_setting_extra;
    if (strSetEx)
    {
        self.thirdView.text=strSetEx;
    }
    else
    {
        self.thirdView.text=@"特么又没有数据";
    }
    self.thirdView.textColor=[UIColor blueColor];
    [self.view addSubview:self.thirdView];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
